<template>
	<view class="content">
		<view class="xuaz">
			<view class="lable-name" style="width: 20%;">姓名</view>
			<view class="lable-select" style="width: 80%;">
				<input type="text" v-model="form.nickname" style="font-size: 14px;" placeholder="请输入姓名"/>
			</view>
		</view>
		<view class="xuaz">
			<view class="lable-name" style="width: 20%;">联系电话</view>
			<view class="lable-select" style="width: 80%;">
				<input type="text" v-model="form.mobile" style="font-size: 14px;" placeholder="请输入联系电话"/>
			</view>
		</view>
		<view class="xuaz">
			<view class="lable-name" style="width: 20%;">身份证号</view>
			<view class="lable-select" style="width: 80%;">
				<input type="text" v-model="form.id_card" style="font-size: 14px;" placeholder="请输入身份证号"/>
			</view>
		</view>
	</view>
	
	<view class="content" style="padding: 1rem;text-align: center;">
		<button style="width: 90%;background: #dd5154;color: white;height: 2.5rem; line-height: 2.5rem;" @click="doProfile()">确认提交</button>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				userInfo:null,
				form:{
					nickname:null,
					id_card:null,
					mobile:null
				},
				user_token:null
				
			};
		},
		onLoad() {
			this.getUserInfo()
		},
		methods: {
			getUserInfo(){
				let that = this
				if(that.userInfo == null){
					uni.getStorage({
						key: 'user_token',
						success: function (res) {
							that.user_token = res.data
							that.checkUser()
						},
						fail: function(res){
							console.log(res)
							uni.showToast({
								title:'请先登录',
								icon:'none',
								success() {
									uni.redirectTo({
										url:'/pages/login/login',
									})
								}
							})
							
						}
					});
				}
			},
			checkUser(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + '/api/user/getUserInfo',
					method:'POST',
					header: {token:that.user_token},
					success(res) {
						if(res.data.code == 401){
							uni.removeStorage({
								key:'user_token',
								success() {
									uni.showToast({
										icon:'none',
										title:'登录已失效,请重新登录',
										success() {
											setTimeout(function(){
												uni.redirectTo({
													url:'/pages/login/login'
												})
											})
										}
									})
								}
							})
						}
						that.userInfo = res.data.data
						that.form.id_card = that.userInfo.id_card
						that.form.nickname = that.userInfo.nickname
						that.form.mobile = that.userInfo.mobile
					},
					fail() {
						uni.showToast({
							title:'网络错误',
							icon:'none',
						})
					}
				})
			},
			doProfile(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + '/api/user/profile',
					data: that.form,
					header: {token:that.userInfo.token},
					method:'POST',
					success(res) {
						if(res.data.code == 1){
							uni.setStorageSync({
								key:'user_info',
								data:res.data.data
							})
							uni.showToast({
								icon:'none',
								title:res.data.msg,
							})
						}else{
							uni.showToast({
								icon:'none',
								title:res.data.msg,
								success(ress) {
									setTimeout(function(){
										uni.navigateTo({
											url:'/pages/my/my'
										})
									},1000)
								}
							})
						}
					}
				})
			},
			uploadImg(data){
				console.log(data)
			},
			back(){
				uni.navigateBack()
			},
			more(){
				uni.navigateTo({
					url:"/pages/withdrawList/withdrawList"
				})
			},
			qiehuan(data){
				console.log(data)
			},
			qiehuanType(data){
				
			},
			jumpPage(){
				uni.navigateTo({
					url:"/pages/myWalletInfo/myWalletInfo"
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #f4f4f4;
	}
	.xuaz{
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 0 0.6rem;
		padding: 1rem;
		border-bottom: 1px solid #f6f6f6 !important;
	}
	.lable-name{
		width: 30%;
		font-weight: bold;
		font-size: 14px;
	}
	.lable-select{
		width: 60%;
		display: flex;
	}
	.content{
		background: #fff;
		display: flex;
		flex-direction: column;
		margin-top: .7rem;
	}
	
	.lable-select >input{
		width: 100%;
	}
</style>
